Imports System.Drawing.Imaging
Imports System.IO

Imports ComponentGo.Calendars

Imports Phoenix.DataAccess
Imports Phoenix.Events
Imports Phoenix.Helpers
Imports Phoenix.Preferences


Namespace Forms

    Public Class EmployeeForm : Inherits ChildFormBase

#Region " Data "
        Public Shadows Property DataSource() As DataSetData.Employee
            Get
                Return CType(MyBase.DataSource, DataSetData.Employee)
            End Get
            Set(ByVal Value As DataSetData.Employee)
                MyBase.DataSource = Value
            End Set
        End Property


        Protected Overrides Function IsDataUpdated() As Boolean
            If mTimeChanged Then
                Return True
            Else
                Return MyBase.IsDataUpdated
            End If
        End Function


        Protected Overrides Sub DoBinding()
            If Not Security.IsAdministrator() Then
                ClearBinding(SecurityTabPage)
            End If

            UpdateSecurityEditCommands()
            ActivateTabPages()
            mCalendarLoaded = False
            mTimeChanged = False


            ComboBoxSecurityLevel.Properties.Items.Add(Security.GetSecurityRoleTitle(0))
            ComboBoxSecurityLevel.Properties.Items.Add(Security.GetSecurityRoleTitle(1))
            ComboBoxSecurityLevel.Properties.Items.Add(Security.GetSecurityRoleTitle(2))
            ComboBoxSecurityLevel.SelectedIndex = 0


            'NameBox.DataBindings.Add("Text", DataSource, "FullName")
            BindWithCapitalization(NameBox, "Text", DataSource, "FullName")


            CommentMemo.DataBindings.Add("Text", DataSource, "Comments")
            AddressMemo.DataBindings.Add("Text", DataSource, "Address")
            PhoneBox.DataBindings.Add("Text", DataSource, "Phone")
            IsAttendantCheckEdit.DataBindings.Add("Checked", DataSource, "IsAttendant")
            IsOperatorCheckEdit.DataBindings.Add("Checked", DataSource, "IsOperator")

            If DataSource.MasterLevel Is Nothing Then
                MasterLevelCombo.SelectedIndex = 0
                DataSource.MasterLevel = MasterLevelCombo.Properties.Items(0)
            Else
                MasterLevelCombo.SelectedItem = DataSource.MasterLevel
            End If
            txtPassword.DataBindings.Add("Text", DataSource, "Password")
            ComboBoxSecurityLevel.DataBindings.Add("SelectedIndex", DataSource, "SecurityLevel")

            ' Photo
            PictureBox.Enabled = False
            PictureBox.Image = Helpers.EmployeeHelper.GetEmployeeImage(DataSource)
            PictureBox.Enabled = True
        End Sub

        Private Sub Index2ML(ByVal sender As Object, ByVal cevent As ConvertEventArgs)
            If Not cevent.DesiredType Is GetType(String) Then Return
            If cevent.Value = 0 Then
                cevent.Value = "Beginner"
            Else
                cevent.Value = AppDataLayer.MasterLevels.FindByMasterLevelID(cevent.Value).LevelName
            End If
        End Sub

        Private Sub IML2Index(ByVal sender As Object, ByVal cevent As ConvertEventArgs)
            If Not cevent.DesiredType Is GetType(Int32) Then Return
            If MasterLevelCombo.SelectedIndex > -1 Then
                cevent.Value = mlList(MasterLevelCombo.SelectedIndex)
            Else
                cevent.Value = 1
            End If
        End Sub

        Public Overrides ReadOnly Property DocumentTitle() As String
            Get
                Return DataSource.FullName()
            End Get
        End Property

        Public Overrides ReadOnly Property DocumentType() As String
            Get
                Return Res.TypeEmployeeDocument
            End Get
        End Property
#End Region

#Region " Private Fields "
        Private mWeekBegin(7) As TimeSpan
        Private mWeekEnd(7) As TimeSpan
        Private mHolyday(7) As Boolean

        Private mBreaks As ComponentGo.Calendars.BreakCollection
        Private dfML As Long = 1
        Private mlList As New ArrayList
#End Region

#Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()


            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call
            UpdateConfiguration()

            For Each l As DataSetData.MasterLevel In AppDataLayer.MasterLevels
                MasterLevelCombo.Properties.Items.Add(l)
            Next

            AHServiceColumn.DisplayFormat.Format = New Lookup.ServiceLookupFormatter
            AHPerformerColumn.DisplayFormat.Format = New Lookup.EmployeeLookupFormatter
            AHOperatorColumn.DisplayFormat.Format = New Lookup.EmployeeLookupFormatter
        End Sub

        'UserControl overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
        Friend WithEvents TabControl As System.Windows.Forms.TabControl
        Friend WithEvents GeneralTabPage As System.Windows.Forms.TabPage
        Friend WithEvents ScheduleTabPage As System.Windows.Forms.TabPage
        Friend WithEvents Calendar As ComponentGo.Calendars.DailyCalendar
        Friend WithEvents SecurityTabPage As System.Windows.Forms.TabPage
        Friend WithEvents lblPassword As System.Windows.Forms.Label
        Friend WithEvents txtPassword As DevExpress.XtraEditors.TextEdit
        Friend WithEvents lblSecurityLevel As System.Windows.Forms.Label
        Friend WithEvents CommentMemo As DevExpress.XtraEditors.MemoEdit
        Friend WithEvents PictureBox As DevExpress.XtraEditors.PictureEdit
        Friend WithEvents AddressMemo As DevExpress.XtraEditors.MemoEdit
        Friend WithEvents AddressLabel As System.Windows.Forms.Label
        Friend WithEvents PhoneLabel As System.Windows.Forms.Label
        Friend WithEvents PhoneBox As DevExpress.XtraEditors.TextEdit
        Friend WithEvents MasterLevelLabel As System.Windows.Forms.Label
        Friend WithEvents FirstNameLabel As System.Windows.Forms.Label
        Friend WithEvents NameBox As DevExpress.XtraEditors.TextEdit
        Friend WithEvents MasterLevelCombo As DevExpress.XtraEditors.ComboBoxEdit
        Friend WithEvents NavigationMonthCalendar As System.Windows.Forms.MonthCalendar
        Friend WithEvents ComboBoxSecurityLevel As DevExpress.XtraEditors.ComboBoxEdit
        Friend WithEvents IsOperatorCheckEdit As DevExpress.XtraEditors.CheckEdit
        Friend WithEvents IsAttendantCheckEdit As DevExpress.XtraEditors.CheckEdit
        Friend WithEvents AppointmentTabPage As System.Windows.Forms.TabPage
        Friend WithEvents AHGrid As DevExpress.XtraGrid.GridControl
        Friend WithEvents AHView As DevExpress.XtraGrid.Views.Grid.GridView
        Friend WithEvents AHIconColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHIconRI As DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
        Friend WithEvents AHDescriptionColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHServiceColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHPerformerColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHDateColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHStartTimeColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHFinishTimeColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHPriceColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHStatusColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHOperatorColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHCommentColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents AHCommentRI As DevExpress.XtraEditors.Repository.RepositoryItemMemoExEdit
        Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
        Friend WithEvents Label4 As System.Windows.Forms.Label
        Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
        Friend WithEvents Label1 As System.Windows.Forms.Label
        Friend WithEvents FreeTimeBox As System.Windows.Forms.GroupBox
        Friend WithEvents AddBusyTimeButton As DevExpress.XtraEditors.SimpleButton
        Friend WithEvents RemoveBusyTimeButton As DevExpress.XtraEditors.SimpleButton
        Friend WithEvents WorkingTimeBox As System.Windows.Forms.GroupBox
        Friend WithEvents RemoveFreeTimeButton As DevExpress.XtraEditors.SimpleButton
        Friend WithEvents AddFreeTimeButton As DevExpress.XtraEditors.SimpleButton
        Friend WithEvents AdditionTimeBox As System.Windows.Forms.GroupBox
        Friend WithEvents RemoveAdditionalTimeButton As DevExpress.XtraEditors.SimpleButton
        Friend WithEvents AddAdditionTimeButton As DevExpress.XtraEditors.SimpleButton

        Private Sub InitializeComponent()
            Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(EmployeeForm))
            Me.TabControl = New System.Windows.Forms.TabControl
            Me.GeneralTabPage = New System.Windows.Forms.TabPage
            Me.AddressMemo = New DevExpress.XtraEditors.MemoEdit
            Me.AddressLabel = New System.Windows.Forms.Label
            Me.PhoneLabel = New System.Windows.Forms.Label
            Me.PhoneBox = New DevExpress.XtraEditors.TextEdit
            Me.MasterLevelLabel = New System.Windows.Forms.Label
            Me.FirstNameLabel = New System.Windows.Forms.Label
            Me.NameBox = New DevExpress.XtraEditors.TextEdit
            Me.MasterLevelCombo = New DevExpress.XtraEditors.ComboBoxEdit
            Me.PictureBox = New DevExpress.XtraEditors.PictureEdit
            Me.CommentMemo = New DevExpress.XtraEditors.MemoEdit
            Me.SecurityTabPage = New System.Windows.Forms.TabPage
            Me.GroupBox1 = New System.Windows.Forms.GroupBox
            Me.Label1 = New System.Windows.Forms.Label
            Me.GroupBox3 = New System.Windows.Forms.GroupBox
            Me.Label4 = New System.Windows.Forms.Label
            Me.IsOperatorCheckEdit = New DevExpress.XtraEditors.CheckEdit
            Me.IsAttendantCheckEdit = New DevExpress.XtraEditors.CheckEdit
            Me.ComboBoxSecurityLevel = New DevExpress.XtraEditors.ComboBoxEdit
            Me.lblSecurityLevel = New System.Windows.Forms.Label
            Me.lblPassword = New System.Windows.Forms.Label
            Me.txtPassword = New DevExpress.XtraEditors.TextEdit
            Me.ScheduleTabPage = New System.Windows.Forms.TabPage
            Me.AdditionTimeBox = New System.Windows.Forms.GroupBox
            Me.RemoveAdditionalTimeButton = New DevExpress.XtraEditors.SimpleButton
            Me.AddAdditionTimeButton = New DevExpress.XtraEditors.SimpleButton
            Me.WorkingTimeBox = New System.Windows.Forms.GroupBox
            Me.AddFreeTimeButton = New DevExpress.XtraEditors.SimpleButton
            Me.RemoveFreeTimeButton = New DevExpress.XtraEditors.SimpleButton
            Me.FreeTimeBox = New System.Windows.Forms.GroupBox
            Me.RemoveBusyTimeButton = New DevExpress.XtraEditors.SimpleButton
            Me.AddBusyTimeButton = New DevExpress.XtraEditors.SimpleButton
            Me.NavigationMonthCalendar = New System.Windows.Forms.MonthCalendar
            Me.Calendar = New ComponentGo.Calendars.DailyCalendar
            Me.AppointmentTabPage = New System.Windows.Forms.TabPage
            Me.AHGrid = New DevExpress.XtraGrid.GridControl
            Me.AHView = New DevExpress.XtraGrid.Views.Grid.GridView
            Me.AHIconColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHIconRI = New DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
            Me.AHDescriptionColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHServiceColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHPerformerColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHDateColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHStartTimeColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHFinishTimeColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHPriceColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHStatusColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHOperatorColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHCommentColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.AHCommentRI = New DevExpress.XtraEditors.Repository.RepositoryItemMemoExEdit
            Me.TabControl.SuspendLayout()
            Me.GeneralTabPage.SuspendLayout()
            CType(Me.AddressMemo.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.PhoneBox.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.NameBox.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.MasterLevelCombo.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.PictureBox.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.CommentMemo.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SecurityTabPage.SuspendLayout()
            CType(Me.IsOperatorCheckEdit.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.IsAttendantCheckEdit.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.ComboBoxSecurityLevel.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.txtPassword.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.ScheduleTabPage.SuspendLayout()
            Me.AdditionTimeBox.SuspendLayout()
            Me.WorkingTimeBox.SuspendLayout()
            Me.FreeTimeBox.SuspendLayout()
            Me.AppointmentTabPage.SuspendLayout()
            CType(Me.AHGrid, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.AHView, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.AHIconRI, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.AHCommentRI, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'TabControl
            '
            Me.TabControl.Controls.Add(Me.GeneralTabPage)
            Me.TabControl.Controls.Add(Me.SecurityTabPage)
            Me.TabControl.Controls.Add(Me.ScheduleTabPage)
            Me.TabControl.Controls.Add(Me.AppointmentTabPage)
            Me.TabControl.Dock = System.Windows.Forms.DockStyle.Fill
            Me.TabControl.Location = New System.Drawing.Point(0, 49)
            Me.TabControl.Name = "TabControl"
            Me.TabControl.SelectedIndex = 0
            Me.TabControl.Size = New System.Drawing.Size(896, 525)
            Me.TabControl.TabIndex = 31
            '
            'GeneralTabPage
            '
            Me.GeneralTabPage.Controls.Add(Me.AddressMemo)
            Me.GeneralTabPage.Controls.Add(Me.AddressLabel)
            Me.GeneralTabPage.Controls.Add(Me.PhoneLabel)
            Me.GeneralTabPage.Controls.Add(Me.PhoneBox)
            Me.GeneralTabPage.Controls.Add(Me.MasterLevelLabel)
            Me.GeneralTabPage.Controls.Add(Me.FirstNameLabel)
            Me.GeneralTabPage.Controls.Add(Me.NameBox)
            Me.GeneralTabPage.Controls.Add(Me.MasterLevelCombo)
            Me.GeneralTabPage.Controls.Add(Me.PictureBox)
            Me.GeneralTabPage.Controls.Add(Me.CommentMemo)
            Me.GeneralTabPage.Location = New System.Drawing.Point(4, 22)
            Me.GeneralTabPage.Name = "GeneralTabPage"
            Me.GeneralTabPage.Size = New System.Drawing.Size(888, 499)
            Me.GeneralTabPage.TabIndex = 0
            Me.GeneralTabPage.Text = "General"
            '
            'AddressMemo
            '
            Me.AddressMemo.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.AddressMemo.EditValue = ""
            Me.AddressMemo.Location = New System.Drawing.Point(104, 112)
            Me.AddressMemo.Name = "AddressMemo"
            Me.AddressMemo.Size = New System.Drawing.Size(432, 64)
            Me.AddressMemo.TabIndex = 4
            '
            'AddressLabel
            '
            Me.AddressLabel.Location = New System.Drawing.Point(16, 112)
            Me.AddressLabel.Name = "AddressLabel"
            Me.AddressLabel.Size = New System.Drawing.Size(88, 20)
            Me.AddressLabel.TabIndex = 66
            Me.AddressLabel.Text = "&Address :"
            Me.AddressLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
            '
            'PhoneLabel
            '
            Me.PhoneLabel.Location = New System.Drawing.Point(16, 80)
            Me.PhoneLabel.Name = "PhoneLabel"
            Me.PhoneLabel.Size = New System.Drawing.Size(88, 20)
            Me.PhoneLabel.TabIndex = 65
            Me.PhoneLabel.Text = "&Phone :"
            Me.PhoneLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
            '
            'PhoneBox
            '
            Me.PhoneBox.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.PhoneBox.EditValue = ""
            Me.PhoneBox.Location = New System.Drawing.Point(104, 80)
            Me.PhoneBox.Name = "PhoneBox"
            Me.PhoneBox.Size = New System.Drawing.Size(432, 20)
            Me.PhoneBox.TabIndex = 3
            '
            'MasterLevelLabel
            '
            Me.MasterLevelLabel.Location = New System.Drawing.Point(16, 48)
            Me.MasterLevelLabel.Name = "MasterLevelLabel"
            Me.MasterLevelLabel.Size = New System.Drawing.Size(88, 23)
            Me.MasterLevelLabel.TabIndex = 63
            Me.MasterLevelLabel.Text = "&Master Level :"
            '
            'FirstNameLabel
            '
            Me.FirstNameLabel.Location = New System.Drawing.Point(16, 16)
            Me.FirstNameLabel.Name = "FirstNameLabel"
            Me.FirstNameLabel.Size = New System.Drawing.Size(88, 20)
            Me.FirstNameLabel.TabIndex = 62
            Me.FirstNameLabel.Text = "&Name :"
            Me.FirstNameLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
            '
            'NameBox
            '
            Me.NameBox.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.NameBox.EditValue = ""
            Me.NameBox.Location = New System.Drawing.Point(104, 16)
            Me.NameBox.Name = "NameBox"
            Me.NameBox.Size = New System.Drawing.Size(432, 20)
            Me.NameBox.TabIndex = 1
            '
            'MasterLevelCombo
            '
            Me.MasterLevelCombo.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.MasterLevelCombo.EditValue = ""
            Me.MasterLevelCombo.Location = New System.Drawing.Point(104, 48)
            Me.MasterLevelCombo.Name = "MasterLevelCombo"
            '
            'MasterLevelCombo.Properties
            '
            Me.MasterLevelCombo.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.MasterLevelCombo.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor
            Me.MasterLevelCombo.Size = New System.Drawing.Size(432, 20)
            Me.MasterLevelCombo.TabIndex = 2
            '
            'PictureBox
            '
            Me.PictureBox.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.PictureBox.Location = New System.Drawing.Point(568, 16)
            Me.PictureBox.Name = "PictureBox"
            '
            'PictureBox.Properties
            '
            Me.PictureBox.Properties.NullText = "No photo"
            Me.PictureBox.Properties.PictureStoreMode = DevExpress.XtraEditors.Controls.PictureStoreMode.Image
            Me.PictureBox.Properties.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom
            Me.PictureBox.Size = New System.Drawing.Size(104, 96)
            Me.PictureBox.TabIndex = 6
            '
            'CommentMemo
            '
            Me.CommentMemo.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                        Or System.Windows.Forms.AnchorStyles.Left) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.CommentMemo.EditValue = ""
            Me.CommentMemo.Location = New System.Drawing.Point(8, 192)
            Me.CommentMemo.Name = "CommentMemo"
            Me.CommentMemo.Size = New System.Drawing.Size(872, 302)
            Me.CommentMemo.TabIndex = 5
            '
            'SecurityTabPage
            '
            Me.SecurityTabPage.Controls.Add(Me.GroupBox1)
            Me.SecurityTabPage.Controls.Add(Me.Label1)
            Me.SecurityTabPage.Controls.Add(Me.GroupBox3)
            Me.SecurityTabPage.Controls.Add(Me.Label4)
            Me.SecurityTabPage.Controls.Add(Me.IsOperatorCheckEdit)
            Me.SecurityTabPage.Controls.Add(Me.IsAttendantCheckEdit)
            Me.SecurityTabPage.Controls.Add(Me.ComboBoxSecurityLevel)
            Me.SecurityTabPage.Controls.Add(Me.lblSecurityLevel)
            Me.SecurityTabPage.Controls.Add(Me.lblPassword)
            Me.SecurityTabPage.Controls.Add(Me.txtPassword)
            Me.SecurityTabPage.Location = New System.Drawing.Point(4, 22)
            Me.SecurityTabPage.Name = "SecurityTabPage"
            Me.SecurityTabPage.Size = New System.Drawing.Size(888, 499)
            Me.SecurityTabPage.TabIndex = 2
            Me.SecurityTabPage.Text = "Security"
            '
            'GroupBox1
            '
            Me.GroupBox1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.GroupBox1.Location = New System.Drawing.Point(96, 128)
            Me.GroupBox1.Name = "GroupBox1"
            Me.GroupBox1.Size = New System.Drawing.Size(776, 3)
            Me.GroupBox1.TabIndex = 67
            Me.GroupBox1.TabStop = False
            '
            'Label1
            '
            Me.Label1.Location = New System.Drawing.Point(8, 120)
            Me.Label1.Name = "Label1"
            Me.Label1.Size = New System.Drawing.Size(72, 16)
            Me.Label1.TabIndex = 66
            Me.Label1.Text = "Status"
            '
            'GroupBox3
            '
            Me.GroupBox3.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.GroupBox3.Location = New System.Drawing.Point(96, 22)
            Me.GroupBox3.Name = "GroupBox3"
            Me.GroupBox3.Size = New System.Drawing.Size(776, 3)
            Me.GroupBox3.TabIndex = 65
            Me.GroupBox3.TabStop = False
            '
            'Label4
            '
            Me.Label4.Location = New System.Drawing.Point(8, 16)
            Me.Label4.Name = "Label4"
            Me.Label4.Size = New System.Drawing.Size(72, 16)
            Me.Label4.TabIndex = 64
            Me.Label4.Text = "Security"
            '
            'IsOperatorCheckEdit
            '
            Me.IsOperatorCheckEdit.Location = New System.Drawing.Point(128, 176)
            Me.IsOperatorCheckEdit.Name = "IsOperatorCheckEdit"
            '
            'IsOperatorCheckEdit.Properties
            '
            Me.IsOperatorCheckEdit.Properties.Caption = "Staff Member can login into the system"
            Me.IsOperatorCheckEdit.Size = New System.Drawing.Size(224, 19)
            Me.IsOperatorCheckEdit.TabIndex = 63
            '
            'IsAttendantCheckEdit
            '
            Me.IsAttendantCheckEdit.Location = New System.Drawing.Point(128, 144)
            Me.IsAttendantCheckEdit.Name = "IsAttendantCheckEdit"
            '
            'IsAttendantCheckEdit.Properties
            '
            Me.IsAttendantCheckEdit.Properties.Caption = "Active"
            Me.IsAttendantCheckEdit.Size = New System.Drawing.Size(176, 19)
            Me.IsAttendantCheckEdit.TabIndex = 62
            '
            'ComboBoxSecurityLevel
            '
            Me.ComboBoxSecurityLevel.Location = New System.Drawing.Point(224, 72)
            Me.ComboBoxSecurityLevel.Name = "ComboBoxSecurityLevel"
            '
            'ComboBoxSecurityLevel.Properties
            '
            Me.ComboBoxSecurityLevel.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.ComboBoxSecurityLevel.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor
            Me.ComboBoxSecurityLevel.Size = New System.Drawing.Size(136, 20)
            Me.ComboBoxSecurityLevel.TabIndex = 61
            '
            'lblSecurityLevel
            '
            Me.lblSecurityLevel.Location = New System.Drawing.Point(128, 72)
            Me.lblSecurityLevel.Name = "lblSecurityLevel"
            Me.lblSecurityLevel.Size = New System.Drawing.Size(88, 23)
            Me.lblSecurityLevel.TabIndex = 60
            Me.lblSecurityLevel.Text = "Security Level :"
            '
            'lblPassword
            '
            Me.lblPassword.Location = New System.Drawing.Point(128, 40)
            Me.lblPassword.Name = "lblPassword"
            Me.lblPassword.Size = New System.Drawing.Size(88, 23)
            Me.lblPassword.TabIndex = 42
            Me.lblPassword.Text = "Password :"
            '
            'txtPassword
            '
            Me.txtPassword.EditValue = ""
            Me.txtPassword.Location = New System.Drawing.Point(224, 40)
            Me.txtPassword.Name = "txtPassword"
            '
            'txtPassword.Properties
            '
            Me.txtPassword.Properties.PasswordChar = Microsoft.VisualBasic.ChrW(42)
            Me.txtPassword.Size = New System.Drawing.Size(136, 20)
            Me.txtPassword.TabIndex = 9
            Me.txtPassword.Tag = ""
            '
            'ScheduleTabPage
            '
            Me.ScheduleTabPage.Controls.Add(Me.AdditionTimeBox)
            Me.ScheduleTabPage.Controls.Add(Me.WorkingTimeBox)
            Me.ScheduleTabPage.Controls.Add(Me.FreeTimeBox)
            Me.ScheduleTabPage.Controls.Add(Me.NavigationMonthCalendar)
            Me.ScheduleTabPage.Controls.Add(Me.Calendar)
            Me.ScheduleTabPage.Location = New System.Drawing.Point(4, 22)
            Me.ScheduleTabPage.Name = "ScheduleTabPage"
            Me.ScheduleTabPage.Size = New System.Drawing.Size(888, 499)
            Me.ScheduleTabPage.TabIndex = 1
            Me.ScheduleTabPage.Text = "Schedule"
            '
            'AdditionTimeBox
            '
            Me.AdditionTimeBox.Controls.Add(Me.RemoveAdditionalTimeButton)
            Me.AdditionTimeBox.Controls.Add(Me.AddAdditionTimeButton)
            Me.AdditionTimeBox.Location = New System.Drawing.Point(8, 384)
            Me.AdditionTimeBox.Name = "AdditionTimeBox"
            Me.AdditionTimeBox.Size = New System.Drawing.Size(144, 96)
            Me.AdditionTimeBox.TabIndex = 8
            Me.AdditionTimeBox.TabStop = False
            Me.AdditionTimeBox.Text = "Additional Working Time"
            '
            'RemoveAdditionalTimeButton
            '
            Me.RemoveAdditionalTimeButton.Location = New System.Drawing.Point(20, 56)
            Me.RemoveAdditionalTimeButton.Name = "RemoveAdditionalTimeButton"
            Me.RemoveAdditionalTimeButton.Size = New System.Drawing.Size(104, 23)
            Me.RemoveAdditionalTimeButton.TabIndex = 6
            Me.RemoveAdditionalTimeButton.Text = "Remove Time"
            '
            'AddAdditionTimeButton
            '
            Me.AddAdditionTimeButton.Location = New System.Drawing.Point(20, 24)
            Me.AddAdditionTimeButton.Name = "AddAdditionTimeButton"
            Me.AddAdditionTimeButton.Size = New System.Drawing.Size(104, 23)
            Me.AddAdditionTimeButton.TabIndex = 5
            Me.AddAdditionTimeButton.Text = "Add Time"
            '
            'WorkingTimeBox
            '
            Me.WorkingTimeBox.Controls.Add(Me.AddFreeTimeButton)
            Me.WorkingTimeBox.Controls.Add(Me.RemoveFreeTimeButton)
            Me.WorkingTimeBox.Location = New System.Drawing.Point(8, 272)
            Me.WorkingTimeBox.Name = "WorkingTimeBox"
            Me.WorkingTimeBox.Size = New System.Drawing.Size(144, 96)
            Me.WorkingTimeBox.TabIndex = 7
            Me.WorkingTimeBox.TabStop = False
            Me.WorkingTimeBox.Text = "Working Time"
            '
            'AddFreeTimeButton
            '
            Me.AddFreeTimeButton.Location = New System.Drawing.Point(20, 56)
            Me.AddFreeTimeButton.Name = "AddFreeTimeButton"
            Me.AddFreeTimeButton.Size = New System.Drawing.Size(104, 23)
            Me.AddFreeTimeButton.TabIndex = 6
            Me.AddFreeTimeButton.Text = "Remove Time"
            '
            'RemoveFreeTimeButton
            '
            Me.RemoveFreeTimeButton.Location = New System.Drawing.Point(20, 24)
            Me.RemoveFreeTimeButton.Name = "RemoveFreeTimeButton"
            Me.RemoveFreeTimeButton.Size = New System.Drawing.Size(104, 23)
            Me.RemoveFreeTimeButton.TabIndex = 5
            Me.RemoveFreeTimeButton.Text = "Add Time"
            '
            'FreeTimeBox
            '
            Me.FreeTimeBox.Controls.Add(Me.RemoveBusyTimeButton)
            Me.FreeTimeBox.Controls.Add(Me.AddBusyTimeButton)
            Me.FreeTimeBox.Location = New System.Drawing.Point(8, 160)
            Me.FreeTimeBox.Name = "FreeTimeBox"
            Me.FreeTimeBox.Size = New System.Drawing.Size(144, 96)
            Me.FreeTimeBox.TabIndex = 6
            Me.FreeTimeBox.TabStop = False
            Me.FreeTimeBox.Text = "Free Time"
            '
            'RemoveBusyTimeButton
            '
            Me.RemoveBusyTimeButton.Location = New System.Drawing.Point(20, 56)
            Me.RemoveBusyTimeButton.Name = "RemoveBusyTimeButton"
            Me.RemoveBusyTimeButton.Size = New System.Drawing.Size(104, 23)
            Me.RemoveBusyTimeButton.TabIndex = 6
            Me.RemoveBusyTimeButton.Text = "Remove Time"
            '
            'AddBusyTimeButton
            '
            Me.AddBusyTimeButton.Location = New System.Drawing.Point(20, 24)
            Me.AddBusyTimeButton.Name = "AddBusyTimeButton"
            Me.AddBusyTimeButton.Size = New System.Drawing.Size(104, 23)
            Me.AddBusyTimeButton.TabIndex = 5
            Me.AddBusyTimeButton.Text = "Add Time"
            '
            'NavigationMonthCalendar
            '
            Me.NavigationMonthCalendar.Location = New System.Drawing.Point(0, 0)
            Me.NavigationMonthCalendar.Name = "NavigationMonthCalendar"
            Me.NavigationMonthCalendar.TabIndex = 0
            '
            'Calendar
            '
            Me.Calendar.AllDayVisible = False
            Me.Calendar.AllowOverlap = False
            Me.Calendar.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                        Or System.Windows.Forms.AnchorStyles.Left) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.Calendar.DateLabelFormat = "{0:ddd} ({0:m})"
            Me.Calendar.DayLineColor = System.Drawing.Color.FromArgb(CType(215, Byte), CType(177, Byte), CType(0, Byte))
            Me.Calendar.EnableEditInPlace = False
            Me.Calendar.ExtraBreakHourColor = System.Drawing.Color.Fuchsia
            Me.Calendar.FirstDate = New Date(2005, 7, 8, 0, 0, 0, 0)
            Me.Calendar.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
            Me.Calendar.FreeDay = ComponentGo.Calendars.FreeDays.None
            Me.Calendar.FreeHourColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(238, Byte), CType(158, Byte))
            Me.Calendar.Location = New System.Drawing.Point(176, 8)
            Me.Calendar.Name = "Calendar"
            Me.Calendar.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
            Me.Calendar.Size = New System.Drawing.Size(712, 488)
            Me.Calendar.TabIndex = 5
            Me.Calendar.VisibleColumns = 7
            '
            'AppointmentTabPage
            '
            Me.AppointmentTabPage.Controls.Add(Me.AHGrid)
            Me.AppointmentTabPage.Location = New System.Drawing.Point(4, 22)
            Me.AppointmentTabPage.Name = "AppointmentTabPage"
            Me.AppointmentTabPage.Size = New System.Drawing.Size(888, 499)
            Me.AppointmentTabPage.TabIndex = 3
            Me.AppointmentTabPage.Text = "Pending Appointments"
            '
            'AHGrid
            '
            Me.AHGrid.Dock = System.Windows.Forms.DockStyle.Fill
            '
            'AHGrid.EmbeddedNavigator
            '
            Me.AHGrid.EmbeddedNavigator.Name = ""
            Me.AHGrid.Location = New System.Drawing.Point(0, 0)
            Me.AHGrid.MainView = Me.AHView
            Me.AHGrid.Name = "AHGrid"
            Me.AHGrid.RepositoryItems.AddRange(New DevExpress.XtraEditors.Repository.RepositoryItem() {Me.AHCommentRI, Me.AHIconRI})
            Me.AHGrid.Size = New System.Drawing.Size(888, 499)
            Me.AHGrid.TabIndex = 1
            Me.AHGrid.Text = "AHGrid"
            '
            'AHView
            '
            Me.AHView.Columns.AddRange(New DevExpress.XtraGrid.Columns.GridColumn() {Me.AHIconColumn, Me.AHDescriptionColumn, Me.AHServiceColumn, Me.AHPerformerColumn, Me.AHDateColumn, Me.AHStartTimeColumn, Me.AHFinishTimeColumn, Me.AHPriceColumn, Me.AHStatusColumn, Me.AHOperatorColumn, Me.AHCommentColumn})
            Me.AHView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus
            Me.AHView.GridControl = Me.AHGrid
            Me.AHView.GroupFormat = "{1}"
            Me.AHView.Name = "AHView"
            Me.AHView.OptionsView.ShowGroupPanel = False
            Me.AHView.OptionsView.ShowIndicator = False
            Me.AHView.OptionsView.ShowVertLines = False
            '
            'AHIconColumn
            '
            Me.AHIconColumn.ColumnEdit = Me.AHIconRI
            Me.AHIconColumn.Name = "AHIconColumn"
            Me.AHIconColumn.Options = CType(((DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly Or DevExpress.XtraGrid.Columns.ColumnOptions.FixedWidth) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHIconColumn.VisibleIndex = 0
            Me.AHIconColumn.Width = 20
            '
            'AHIconRI
            '
            Me.AHIconRI.AutoHeight = False
            Me.AHIconRI.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.AHIconRI.Items.AddRange(New Object() {New DevExpress.XtraEditors.Controls.ImageComboBoxItem("", Nothing, 8)})
            Me.AHIconRI.Name = "AHIconRI"
            '
            'AHDescriptionColumn
            '
            Me.AHDescriptionColumn.Caption = "Description"
            Me.AHDescriptionColumn.FieldName = "Description"
            Me.AHDescriptionColumn.Name = "AHDescriptionColumn"
            Me.AHDescriptionColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHDescriptionColumn.VisibleIndex = 1
            Me.AHDescriptionColumn.Width = 69
            '
            'AHServiceColumn
            '
            Me.AHServiceColumn.Caption = "Service"
            Me.AHServiceColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom
            Me.AHServiceColumn.FieldName = "ServiceID"
            Me.AHServiceColumn.Name = "AHServiceColumn"
            Me.AHServiceColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHServiceColumn.VisibleIndex = 2
            Me.AHServiceColumn.Width = 69
            '
            'AHPerformerColumn
            '
            Me.AHPerformerColumn.Caption = "Staff member"
            Me.AHPerformerColumn.FieldName = "PerformerID"
            Me.AHPerformerColumn.Name = "AHPerformerColumn"
            Me.AHPerformerColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHPerformerColumn.VisibleIndex = 3
            Me.AHPerformerColumn.Width = 69
            '
            'AHDateColumn
            '
            Me.AHDateColumn.Caption = "Date"
            Me.AHDateColumn.DisplayFormat.FormatString = "d"
            Me.AHDateColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime
            Me.AHDateColumn.FieldName = "StartTime"
            Me.AHDateColumn.Name = "AHDateColumn"
            Me.AHDateColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHDateColumn.VisibleIndex = 4
            Me.AHDateColumn.Width = 69
            '
            'AHStartTimeColumn
            '
            Me.AHStartTimeColumn.Caption = "Started At"
            Me.AHStartTimeColumn.DisplayFormat.FormatString = "t"
            Me.AHStartTimeColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime
            Me.AHStartTimeColumn.FieldName = "StartTime"
            Me.AHStartTimeColumn.Name = "AHStartTimeColumn"
            Me.AHStartTimeColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHStartTimeColumn.VisibleIndex = 5
            Me.AHStartTimeColumn.Width = 69
            '
            'AHFinishTimeColumn
            '
            Me.AHFinishTimeColumn.Caption = "Finished At"
            Me.AHFinishTimeColumn.DisplayFormat.FormatString = "t"
            Me.AHFinishTimeColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime
            Me.AHFinishTimeColumn.FieldName = "FinishTime"
            Me.AHFinishTimeColumn.Name = "AHFinishTimeColumn"
            Me.AHFinishTimeColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHFinishTimeColumn.VisibleIndex = 6
            Me.AHFinishTimeColumn.Width = 69
            '
            'AHPriceColumn
            '
            Me.AHPriceColumn.Caption = "Price"
            Me.AHPriceColumn.DisplayFormat.FormatString = "c2"
            Me.AHPriceColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric
            Me.AHPriceColumn.FieldName = "ServiceCost"
            Me.AHPriceColumn.Name = "AHPriceColumn"
            Me.AHPriceColumn.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHPriceColumn.VisibleIndex = 7
            Me.AHPriceColumn.Width = 69
            '
            'AHStatusColumn
            '
            Me.AHStatusColumn.Caption = "Status"
            Me.AHStatusColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom
            Me.AHStatusColumn.FieldName = "BillID"
            Me.AHStatusColumn.Name = "AHStatusColumn"
            Me.AHStatusColumn.Options = CType((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHStatusColumn.VisibleIndex = 8
            Me.AHStatusColumn.Width = 69
            '
            'AHOperatorColumn
            '
            Me.AHOperatorColumn.Caption = "Operator"
            Me.AHOperatorColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom
            Me.AHOperatorColumn.FieldName = "OperatorID"
            Me.AHOperatorColumn.Name = "AHOperatorColumn"
            Me.AHOperatorColumn.Options = CType((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHOperatorColumn.VisibleIndex = 9
            '
            'AHCommentColumn
            '
            Me.AHCommentColumn.Caption = "Comment"
            Me.AHCommentColumn.ColumnEdit = Me.AHCommentRI
            Me.AHCommentColumn.FieldName = "Comment"
            Me.AHCommentColumn.Name = "AHCommentColumn"
            Me.AHCommentColumn.Options = CType((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.AHCommentColumn.VisibleIndex = 10
            Me.AHCommentColumn.Width = 82
            '
            'AHCommentRI
            '
            Me.AHCommentRI.AutoHeight = False
            Me.AHCommentRI.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.AHCommentRI.Name = "AHCommentRI"
            '
            'EmployeeForm
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(896, 574)
            Me.Controls.Add(Me.TabControl)
            Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
            Me.MinimumSize = New System.Drawing.Size(616, 472)
            Me.Name = "EmployeeForm"
            Me.Text = "Unknown - "
            Me.Controls.SetChildIndex(Me.TabControl, 0)
            Me.TabControl.ResumeLayout(False)
            Me.GeneralTabPage.ResumeLayout(False)
            CType(Me.AddressMemo.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.PhoneBox.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.NameBox.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.MasterLevelCombo.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.PictureBox.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.CommentMemo.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            Me.SecurityTabPage.ResumeLayout(False)
            CType(Me.IsOperatorCheckEdit.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.IsAttendantCheckEdit.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.ComboBoxSecurityLevel.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.txtPassword.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ScheduleTabPage.ResumeLayout(False)
            Me.AdditionTimeBox.ResumeLayout(False)
            Me.WorkingTimeBox.ResumeLayout(False)
            Me.FreeTimeBox.ResumeLayout(False)
            Me.AppointmentTabPage.ResumeLayout(False)
            CType(Me.AHGrid, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.AHView, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.AHIconRI, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.AHCommentRI, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)

        End Sub
#End Region

#Region " Event Handlers "
        Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If DesignMode Then Return

            AddHandler PhoenixApplication.AppNotification, AddressOf Application_Notification
        End Sub

#End Region

#Region " General Tab Page "
        Private Sub PictureBox_EditValueChanged(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox.EditValueChanged
            If Not PictureBox.Enabled Then Return

            If PictureBox.Image Is Nothing Then
                PictureBox.Image = Helpers.EmployeeHelper.GetDefaultImage()
                Helpers.EmployeeHelper.SetEmployeeImage(DataSource, Nothing)
            Else
                Helpers.EmployeeHelper.SetEmployeeImage(DataSource, PictureBox.Image)
            End If
        End Sub

#End Region

#Region " Schedule Tab Page "
        Private Sub ShowDate(ByVal d As Date)
            Dim wd As DayOfWeek = d.DayOfWeek

            d = d.Subtract(TimeSpan.FromDays(wd))

            Calendar.FirstDate = d
        End Sub

        Private Sub NavigationMonthCalendar_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles NavigationMonthCalendar.DateSelected
            ShowDate(e.Start)
        End Sub



        Private mCalendarLoaded As Boolean = False
        Private mTimeChanged As Boolean = False
        Private mBreakManagers(6) As BreakManager
        Private mExtraBreakManagers(6) As BreakManager
        Private Shared TimeSpanDay As TimeSpan = TimeSpan.FromHours(24)
        Private mBusyTimeDS As DataSetAppointments

        Private Sub LoadSchedule()
            If mCalendarLoaded Then Return

            LoadTimes()
            LoadExtraTimes()

            mBusyTimeDS = AppDataLayer.GetBusyAndAdditionalTimes(DataSource.EmployeeID)
            Calendar.Appointments.Clear()
            For Each bt As DataSetAppointments.BusyTime In mBusyTimeDS.BusyTimes
                Dim ca As New Appointment
                ca.DateBegin = bt.ExactDate.AddMinutes(bt.StartTime)
                ca.DateEnd = bt.ExactDate.AddMinutes(bt.FinishTime)
                ca.Text = bt.Descript
                If bt.Busy Then
                    ca.BackColor = AppConfig.BreakBackColor
                    ca.ForeColor = AppConfig.BreakForeColor
                Else
                    ca.BackColor = AppConfig.AdditionalTimeBackColor
                    ca.ForeColor = AppConfig.AdditionalTimeForeColor
                End If
                ca.Tag = bt
                Calendar.Appointments.Add(ca)
            Next

            mCalendarLoaded = True
            mTimeChanged = False
            ShowDate(Today)
        End Sub

        Private Sub LoadTimes()
            For i As Integer = 0 To 6
                mBreakManagers(i) = New BreakManager
            Next

            For Each st As DataSetData.SalonTime In AppDataLayer.SalonTimes
                mBreakManagers(st.DayOfWeek).AddWorkTime(TimeSpan.FromMinutes(st.StartTime), TimeSpan.FromMinutes(st.FinishTime))
            Next
        End Sub

        Private Sub LoadExtraTimes()
            For i As Integer = 0 To 6
                mExtraBreakManagers(i) = New BreakManager(True)
            Next

            For Each et As DataSetData.EmployeeTime In AppDataLayer.EmployeeTimes.Select("EmployeeID = " & DataSource.EmployeeID)
                mExtraBreakManagers(et.DayOfWeek).AddBreak(TimeSpan.FromMinutes(et.StartTime), TimeSpan.FromMinutes(et.FinishTime))
            Next
        End Sub

        Private Sub PinBusyTime(ByVal app As Appointment, ByVal IsBusy As Boolean)
            Dim bt As DataSetAppointments.BusyTime = mBusyTimeDS.BusyTimes.NewBusyTime
            bt.ExactDate = app.DateBegin.Date
            bt.EmployeeID = DataSource.EmployeeID
            bt.StartTime = app.DateBegin.TimeOfDay.TotalMinutes
            bt.FinishTime = app.DateEnd.TimeOfDay.TotalMinutes
            bt.Descript = app.Text
            bt.Busy = IsBusy
            app.Tag = bt
        End Sub


        Private Sub UpdateBusyTimes()
            For Each app As Appointment In Calendar.Appointments
                Dim bt As DataSetAppointments.BusyTime = app.Tag
                If bt.RowState = DataRowState.Detached Then
                    mBusyTimeDS.BusyTimes.AddBusyTime(bt)
                End If
            Next
            AppDataLayer.UpdateBusyTimes(mBusyTimeDS.BusyTimes)
        End Sub

        Private Sub UpdateSchedule()
            For i As Integer = 0 To 6
                If mExtraBreakManagers(i).Modified Then
                    UpdateDaySchedule(i, mExtraBreakManagers(i))
                End If
            Next
        End Sub


        Private Sub UpdateDaySchedule(ByVal DayOfWeek As Integer, ByVal man As BreakManager)
            'Clear old schedule
            Dim rows() As DataRow = AppDataLayer.EmployeeTimes.Select(String.Format("DayOfWeek={0} and EmployeeID={1}", DayOfWeek, DataSource.EmployeeID))
            For i As Integer = 0 To rows.Length - 1
                rows(i).Delete()
            Next

            'Create a new schedule
            Dim et As DataSetData.EmployeeTime

            For Each b As Break In man.Breaks
                et = AppDataLayer.EmployeeTimes.NewEmployeeTime
                et.DayOfWeek = DayOfWeek
                et.StartTime = b.BeginBreak.TotalMinutes
                et.FinishTime = b.EndBreak.TotalMinutes
                et.Employee = DataSource
                AppDataLayer.EmployeeTimes.AddEmployeeTime(et)
            Next

            Try
                AppDataLayer.UpdateEmployeeTimes(AppDataLayer.EmployeeTimes)
            Catch ex As Exception
                AppDataLayer.EmployeeTimes.RejectChanges()
                Throw
            End Try
        End Sub

        Private Sub ScheduleCalendar_GetDayInfo(ByVal sender As Object, ByVal args As ComponentGo.Calendars.GetDayInfoEventArgs) Handles Calendar.GetDayInfo
            args.WorkHourBegin = TimeSpan.Zero
            args.WorkHourEnd = TimeSpanDay

            args.Breaks.AddRange(mBreakManagers(args.Date.DayOfWeek).Breaks)
            args.Breaks.AddRange(mExtraBreakManagers(args.Date.DayOfWeek).Breaks)
        End Sub


        Private Sub AddAdditionTimeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddAdditionTimeButton.Click
            Dim breakForm As EditBreakForm

            If Calendar.SelectedDateBegin <> Calendar.SelectedDateEnd Then
                If Calendar.SelectedDateEnd.Date <> Calendar.SelectedDateBegin.Date Then
                    breakForm = New EditBreakForm(Calendar.SelectedDateBegin, Calendar.SelectedDateBegin)
                Else
                    breakForm = New EditBreakForm(Calendar.SelectedDateBegin, Calendar.SelectedDateEnd)
                End If
            Else
                breakForm = New EditBreakForm(Now, Now.AddMinutes(30))
            End If

            If breakForm.ShowDialog() = DialogResult.OK Then
                Dim ca As New Appointment
                ca.DateBegin = breakForm.BeginTime
                ca.DateEnd = breakForm.EndTime
                ca.Text = breakForm.Description
                If ca.Text.Trim() = String.Empty Then
                    ca.Text = Res.DefaultAdditionalTimeDecription
                End If
                ca.BackColor = AppConfig.AdditionalTimeBackColor
                ca.ForeColor = AppConfig.AdditionalTimeForeColor
                PinBusyTime(ca, False)
                Calendar.Appointments.Add(ca)

                mTimeChanged = True
            End If
        End Sub

        Private Sub RemoveAdditionalTimeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveAdditionalTimeButton.Click
            RemoveSelectedTimes(False)
        End Sub



        Private Sub AddBusyTimeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddBusyTimeButton.Click
            Dim breakForm As EditBreakForm

            If Calendar.SelectedDateBegin <> Calendar.SelectedDateEnd Then
                If Calendar.SelectedDateEnd.Date <> Calendar.SelectedDateBegin.Date Then
                    breakForm = New EditBreakForm(Calendar.SelectedDateBegin, Calendar.SelectedDateBegin)
                Else
                    breakForm = New EditBreakForm(Calendar.SelectedDateBegin, Calendar.SelectedDateEnd)
                End If
            Else
                breakForm = New EditBreakForm(Now, Now.AddMinutes(30))
            End If

            If breakForm.ShowDialog() = DialogResult.OK Then
                Dim ca As New Appointment
                ca.DateBegin = breakForm.BeginTime
                ca.DateEnd = breakForm.EndTime
                ca.Text = breakForm.Description
                If ca.Text.Trim() = String.Empty Then
                    ca.Text = Res.DefaultBreakDecription
                End If
                ca.BackColor = AppConfig.BreakBackColor
                ca.ForeColor = AppConfig.BreakForeColor
                PinBusyTime(ca, True)
                Calendar.Appointments.Add(ca)

                mTimeChanged = True
            End If
        End Sub

        Private Sub RemoveBusyTimeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveBusyTimeButton.Click
            RemoveSelectedTimes(True)
        End Sub


        Private Sub AddFreeTimeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddFreeTimeButton.Click
            mTimeChanged = True

            Dim sdb As DateTime = Calendar.SelectedDateBegin
            Dim sde As DateTime = Calendar.SelectedDateEnd

            If sdb.DayOfWeek = sde.DayOfWeek Then
                mExtraBreakManagers(sdb.DayOfWeek).AddBreak(sdb.TimeOfDay, sde.TimeOfDay)
            Else
                mExtraBreakManagers(sdb.DayOfWeek).AddBreak(sdb.TimeOfDay, TimeSpanDay)
                For wd As Integer = sdb.DayOfWeek + 1 To sde.DayOfWeek - 1
                    mExtraBreakManagers(wd).AddBreak(TimeSpan.Zero, TimeSpanDay)
                Next
                mExtraBreakManagers(sde.DayOfWeek).AddBreak(TimeSpan.Zero, sde.TimeOfDay)
            End If

            Calendar.Invalidate()
        End Sub


        Private Sub RemoveFreeTimeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveFreeTimeButton.Click
            mTimeChanged = True

            Dim sdb As DateTime = Calendar.SelectedDateBegin
            Dim sde As DateTime = Calendar.SelectedDateEnd

            If sdb.DayOfWeek = sde.DayOfWeek Then
                mExtraBreakManagers(sdb.DayOfWeek).RemoveBreak(sdb.TimeOfDay, sde.TimeOfDay)
            Else
                mExtraBreakManagers(sdb.DayOfWeek).RemoveBreak(sdb.TimeOfDay, TimeSpanDay)
                For wd As Integer = sdb.DayOfWeek + 1 To sde.DayOfWeek - 1
                    mExtraBreakManagers(wd).RemoveBreak(TimeSpan.Zero, TimeSpanDay)
                Next
                mExtraBreakManagers(sde.DayOfWeek).RemoveBreak(TimeSpan.Zero, sde.TimeOfDay)
            End If

            Calendar.Invalidate()
        End Sub

        Private Sub Calendar_AppointmentChanged(ByVal sender As Object, ByVal args As ComponentGo.Calendars.AppointmentEventArgs) Handles Calendar.AppointmentChanged
            If args.Appointment.Tag Is Nothing Then Return

            Dim bt As DataSetAppointments.BusyTime = args.Appointment.Tag
            bt.ExactDate = args.Appointment.DateBegin.Date
            bt.StartTime = args.Appointment.DateBegin.TimeOfDay.TotalMinutes
            bt.FinishTime = args.Appointment.DateEnd.TimeOfDay.TotalMinutes
            bt.Descript = args.Appointment.Text

            mTimeChanged = True
        End Sub


        Private Sub Calendar_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Calendar.MouseDown
            'Return
            If (e.Button = MouseButtons.Left) And (e.Clicks > 1) Then
                Dim ca As Appointment = Calendar.HitAppointmentTest(New Point(e.X, e.Y))
                If Not ca Is Nothing Then
                    Dim breakForm As New EditBreakForm(ca.DateBegin, ca.DateEnd, ca.Text)
                    If breakForm.ShowDialog() = DialogResult.OK Then
                        ca.DateBegin = breakForm.BeginTime
                        ca.DateEnd = breakForm.EndTime
                        ca.Text = breakForm.Description

                        Dim bt As DataSetAppointments.BusyTime = ca.Tag
                        If ca.Text.Trim() = String.Empty Then
                            If bt.Busy Then
                                ca.Text = Res.DefaultBreakDecription
                            Else
                                ca.Text = Res.DefaultAdditionalTimeDecription
                            End If
                        End If

                        bt.ExactDate = ca.DateBegin.Date
                        bt.StartTime = ca.DateBegin.TimeOfDay.TotalMinutes
                        bt.FinishTime = ca.DateEnd.TimeOfDay.TotalMinutes
                        bt.Descript = ca.Text

                        mTimeChanged = True
                    End If
                End If
            End If
        End Sub


        Private Sub Calendar_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Calendar.KeyDown
            If e.KeyCode = Keys.Delete Then
                RemoveSelectedTimes(True)
                RemoveSelectedTimes(False)
            End If
        End Sub

        Private Sub RemoveSelectedTimes(ByVal busy As Boolean)
            Dim i As Integer = 0
            While i < Calendar.Appointments.Count
                Dim app As Appointment = Calendar.Appointments(i)
                If app.Selected Then
                    Dim bt As DataSetAppointments.BusyTime = app.Tag
                    If bt.Busy = busy Then
                        If bt.RowState <> DataRowState.Detached Then
                            bt.Delete()
                        End If
                        Calendar.Appointments.RemoveAt(i)
                        mTimeChanged = True
                    Else
                        i += 1
                    End If
                Else
                    i += 1
                End If
            End While
        End Sub

#End Region

#Region " Life-Cycle Routines "

        Protected Overrides Sub DoSaving()
            AppDataLayer.DoInTransaction(AddressOf UpdateEmployee)
        End Sub

        Public Sub UpdateEmployee()
            EmployeeHelper.UpdateEmployee(DataSource, Me)
            If mTimeChanged Then
                UpdateBusyTimes()
                UpdateSchedule()
                AppRaiseEvent(Me, New PhoenixEventArgs(DataSource, PhoenixEventCode.ScheduleChanged))
                mTimeChanged = False
            End If
        End Sub

        Protected Overrides Sub OnDelete()
            Helpers.EmployeeHelper.DeleteEmployee(DataSource, Me)
        End Sub

        Protected Overrides Function CreateNewRow() As DataRow
            Dim em As DataSetData.Employee = AppDataLayer.Employees.NewEmployee
            em.FullName = Res.NewEmployeeDefaultName

            Return em
        End Function

        Protected Overrides Sub LoadPreferences(ByVal pref As IPreferencesNode)
            MyBase.LoadPreferences(pref)

            Dim node As IPreferencesNode
            Dim ba As Byte()


            ' AHGrid
            node = pref.GetNodeForPath(AHGrid.Name)
            ba = node.GetByteArray("AHGrid", Nothing) : If Not ba Is Nothing Then AHView.RestoreLayoutFromStream(New MemoryStream(ba))
        End Sub

        Protected Overrides Sub SavePreferences(ByVal pref As IPreferencesNode)
            Dim node As IPreferencesNode
            Dim ms As MemoryStream

            ' AHGrid
            node = pref.GetNodeForPath(AHGrid.Name)
            ms = New MemoryStream : AHView.SaveLayoutToStream(ms) : node.Item("AHGrid") = ms.ToArray()

            MyBase.SavePreferences(pref)
        End Sub
#End Region

#Region " Others "
        Private Sub ActivateTabPages()
            If Not Security.IsAdministrator Then
                TabControl.TabPages.Remove(SecurityTabPage)
            End If
            TabControl.SelectedTab = TabControl.TabPages(0)
        End Sub

        Protected Overrides Sub UpdateSecurityEditCommands()
            If DataSource.Sys Then
                DeleteBarItem.Enabled = False
            Else
                DeleteBarItem.Enabled = Security.CanDeleteEmployee
            End If
            SaveBarItem.Enabled = Security.CanEditEmployee
            SaveCloseBarItem.Enabled = Security.CanEditEmployee
            SaveNewBarItem.Enabled = Security.CanEditEmployee

            NameBox.Properties.ReadOnly = Not Security.CanEditEmployee
            MasterLevelCombo.Properties.ReadOnly = Not Security.CanEditEmployee
            PhoneBox.Properties.ReadOnly = Not Security.CanEditEmployee
            AddressMemo.Properties.ReadOnly = Not Security.CanEditEmployee
            CommentMemo.Properties.ReadOnly = Not Security.CanEditEmployee

            IsAttendantCheckEdit.Enabled = Not DataSource.Sys
            IsAttendantCheckEdit.Properties.ReadOnly = Not Security.IsAdministrator
            IsOperatorCheckEdit.Properties.ReadOnly = Not Security.IsAdministrator
        End Sub

        Private Sub Application_Notification(ByVal sender As Object, ByVal e As PhoenixEventArgs)
            If e.EventCode = PhoenixEventCode.ConfigurationChanged Then
                UpdateConfiguration()
            End If
        End Sub

        Private Sub UpdateConfiguration()
            Calendar.SelectedAppointmentColor = AppConfig.SelectedAppointmentBackColor
            Calendar.SelectedAppointmentTextColor = AppConfig.SelectedAppointmentForeColor
            Calendar.WorkHourColor = AppConfig.WorkHourColor
            Calendar.WorkHourColorSecond = AppConfig.WorkHourColor2
            Calendar.FreeHourColor = AppConfig.FreeHourColor
            Calendar.HoursResolution = AppConfig.ScheduleResolution
            Calendar.FreeHourColor = AppConfig.FreeHourColor
            Calendar.ExtraBreakHourColor = AppConfig.ExtraFreeHourColor
            Calendar.WorkHourColorSecond = AppConfig.WorkHourColor2

            For Each app As Appointment In Calendar.Appointments
                app.BackColor = AppConfig.BreakBackColor
                app.LineColor = AppConfig.BreakForeColor
                app.ForeColor = AppConfig.BreakForeColor
            Next
        End Sub

        Protected Overrides Sub OnApplicationEvent(ByVal sender As Object, ByVal e As Events.PhoenixEventArgs)
            If (e.EventCode = PhoenixEventCode.ScheduleChanged) And (e.EventData Is Nothing) And mCalendarLoaded Then
                LoadTimes()
                Calendar.Invalidate()
            ElseIf e.IsBizEvent Then
                OnBizEvent(e)
            End If
        End Sub

        Private Sub OnBizEvent(ByVal e As Events.PhoenixEventArgs)
            If (TypeOf e.EventData Is DataSetAppointments.Appointment) And AHValid Then
                Dim app As DataSetAppointments.Appointment = e.EventData
                Dim ds As DataSetAppointments.AppointmentsDataTable = AHGrid.DataSource

                If app.Table Is ds Then Exit Sub

                UpdateAppointmentHistory()
            End If
        End Sub

#End Region

#Region " Appointments Tab Page "
        Private mAHValid As Boolean = False
        Private Property AHValid() As Boolean
            Get
                If AHGrid.DataSource Is Nothing Then Return False
                Return mAHValid
            End Get
            Set(ByVal Value As Boolean)
                If Not Value Then
                    AHGrid.DataSource = Nothing
                End If
                mAHValid = Value
            End Set
        End Property



        Private Sub TabControl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl.SelectedIndexChanged
            If TabControl.SelectedTab Is ScheduleTabPage Then
                LoadSchedule()
            ElseIf TabControl.SelectedTab Is AppointmentTabPage Then
                LoadAppointmentHistory()
            End If
        End Sub

        Private Sub LoadAppointmentHistory()
            If AHValid = True Then Return
            If DataSource.RowState = DataRowState.Detached Then Return

            AHGrid.DataSource = AppDataLayer.GetEmployeePendingAppointments(DataSource.EmployeeID).Appointments
            mAHValid = True
        End Sub

        Private Sub UpdateAppointmentHistory()
            If AHValid Then
                AHValid = False
                If TabControl.SelectedTab Is AppointmentTabPage Then
                    LoadAppointmentHistory()
                End If
            End If
        End Sub

        Private Sub AHView_CustomDrawCell(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) Handles AHView.CustomDrawCell
            If e.Column Is AHStatusColumn Then
                e.DisplayText = AppointmentHelper.GetAppointmentStatusString(AHView.GetDataRow(e.RowHandle))
            End If
        End Sub

        Private Sub AHView_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles AHView.MouseDown
            If (e.Clicks > 1) And (e.Button = MouseButtons.Left) Then
                Dim hitInfo As DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo = AHView.CalcHitInfo(New Point(e.X, e.Y))

                If hitInfo.RowHandle >= 0 Then
                    Dim row As DataRow = AHView.GetDataRow(hitInfo.RowHandle)

                    If Not row Is Nothing Then
                        AppointmentForm.OpenForm(row)
                    End If
                End If
            End If
        End Sub
#End Region

        Private Sub MasterLevelCombo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MasterLevelCombo.SelectedIndexChanged
            DataSource.MasterLevel = MasterLevelCombo.SelectedItem
        End Sub


        'Private Sub CheckTimes()
        '    Dim deleted As Integer = 0
        '    Dim added As Integer = 0
        '    Dim modified As Integer = 0

        '    For Each t As DataSetData.EmployeeTime In mBusyTimeDS.BusyTimes
        '        If t.RowState = DataRowState.Added Then
        '            added = added + 1
        '        ElseIf t.RowState = DataRowState.Deleted Then
        '            deleted = deleted + 1
        '        ElseIf t.RowState = DataRowState.Modified Then
        '            modified = modified + 1
        '        End If
        '    Next

        '    Debug.WriteLine(deleted)
        '    Debug.WriteLine(added)
        '    Debug.WriteLine(modified)
        'End Sub

    End Class
End Namespace